package com.yanqu.road.server.cmd.activity.curio;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cangbao.CurioProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.curio.CurioModule;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = CurioProto.CurioLotteryDrawReqMsg.class, respMsg = CurioProto.CurioLotteryDrawRespMsg.class)
@Cmd(code = Protocol.S_CURIO_LOTTERY_DRAW, desc = "淘宝")
public class CurioLotteryDrawCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CurioProto.CurioLotteryDrawReqMsg reqMsg = CurioProto.CurioLotteryDrawReqMsg.parseFrom(packet.getBytes());
        if(reqMsg.getType() < 0 || reqMsg.getType() > 2){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }
        ret = player.getModule(CurioModule.class).draw(reqMsg.getType());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_CURIO_LOTTERY_DRAW, CurioProto.CurioLotteryDrawRespMsg.newBuilder().setRet(ret));
        }
    }
}
